Skip to content

fix(resolvers): ignored priorities no longer discard all EIDs in multi-node targeting - #382

Merged
jrosendahl-opt merged 2 commits into
masterfrom
fix/multi-targeting-ignored-priority
Nov 11, 2026
Merged

jrosendahl-opt merged 2 commits into
masterfrom
fix/multi-targeting-ignored-priority

Conversation

@jrosendahl-opt

Copy link
Copy Markdown
Contributor

Why

In priority mode, resolveMultiNodeTargeting returned no EIDs at all whenever a rule with no priority (or priority <= 0) resolved any EIDs, even if priority 1+ rules also resolved. The README's own example (priority 1, priority 2, and one unprioritized rule) hits this.

Cause: ignored rules were stored under key 0 (Math.max(0, priority)). Key 0 sorted first, was selected, and then failed the if (priority) check, so nothing was pushed.

Found while auditing the README against the code.

What Changed

  • lib/core/resolvers/resolveMultiTargeting.ts: exclude priorities below 1 from selection, and check priority !== undefined instead of truthiness.
  • lib/core/resolvers/resolveMultiTargeting.test.ts: regression test mixing priorities 1, 2, unset and -1; expects only the priority-1 EIDs, sources and resolved IDs.

How to Test

  • npx jest lib/core/resolvers. The new test fails on master (returns []) and passes with the fix.

  • Full suite: 701/701 passing; tsc and prettier clean.

  • Tested

  • Docs updated (N/A: behaviour now matches the documented "priorities ≤ 0 are ignored")

Notes

  • Ignored rules still merge their ortb2.user.data (segments) into the result, unchanged by this PR. Worth deciding whether "ignored" should drop those too.

  • Customer bundles that mix prioritized and unprioritized rules will start receiving EIDs they were previously losing.

  • Breaking change

  • Requires release

🤖 Generated with Claude Code

…i-node targeting

In priority mode, rules with no priority (or priority <= 0) were stored
under key 0. Key 0 sorted first and then failed the `if (priority)` check,
so any ignored rule that returned EIDs caused the resolver to return no
EIDs at all, even when priority 1+ rules resolved. Exclude priorities
below 1 from selection and check for undefined explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jrosendahl-opt
jrosendahl-opt requested review from a team as code owners November 10, 2026 18:29
Comment on lines 125 to 129
// Priorities below 1 are ignored and must not be selected
const priority = Array.from(eidsByPriority.keys())
.filter((x) => x >= 1 && eidsByPriority.get(x)?.length)
.sort((a, b) => a - b)
.filter((x) => eidsByPriority.get(x)?.length)
.shift();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is actually not accurate, since line 33 has:

return rules.some((x) => x.priority) ? resolvePriorityTargeting(rules) : resolveAggregateTargeting(rules);

This will make it so that 0 counts as no priority and -1 counts as priority. The new filter only ever runs if its set to priority so we never actually check the below -1 rule in that case

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of an edge case cause I dont think we normally use negative priorities, but Im just going by unix nice conventions. Approving the PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed comment

…priority mode

Mode selection uses a truthiness check, so all-0/unset rules are aggregated
while a negative priority switches to priority mode. Reword both comments
to say so, and fix the "threated" typo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jrosendahl-opt
jrosendahl-opt merged commit b3b29ff into master Nov 11, 2026
7 checks passed
@jrosendahl-opt
jrosendahl-opt deleted the fix/multi-targeting-ignored-priority branch November 11, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants